﻿#region Copyright (c) 2003 - 2008, Andreas Mueller
/////////////////////////////////////////////////////////////////////////////////////////
// 
// Copyright (c) 2003 - 2008, Andreas Mueller.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
//    Andreas Mueller - initial API and implementation
//
// 
// This software is derived from software bearing the following
// restrictions:
// 
// Copyright (c) 1994
// Hewlett-Packard Company
// 
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation.  Hewlett-Packard Company makes no
// representations about the suitability of this software for any
// purpose.  It is provided "as is" without express or implied warranty.
// 
// 
// Copyright (c) 1996,1997
// Silicon Graphics Computer Systems, Inc.
// 
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation.  Silicon Graphics makes no
// representations about the suitability of this software for any
// purpose.  It is provided "as is" without express or implied warranty.
// 
// 
// (C) Copyright Nicolai M. Josuttis 1999.
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// 
/////////////////////////////////////////////////////////////////////////////////////////
#endregion

using NUnit.Framework;
using NStl.Collections;
using NUnit.Framework.SyntaxHelpers;
using System.Collections.Generic;
using System.Collections;
using System;

namespace NStl.NUnit.ContainerFixture.HashMap
{
    [TestFixture, Obsolete]
    public class HashMapFixture
    {
        [Test]
        public void Count()
        {
            HashMap<int, int> hm = new HashMap<int, int>();

            Assert.That(hm.Count, Is.EqualTo(0));

            hm.Insert(2, 2);
            Assert.That(hm.Count, Is.EqualTo(1));

            hm.Insert(2, 4);
            Assert.That(hm.Count, Is.EqualTo(1));
        }
        [Test]
        public void ToArray()
        {
            HashMap<int, int> hm = new HashMap<int, int>();

            List<KeyValuePair<int, int>> refCollection = new List<KeyValuePair<int, int>>();
            for(int i = 0; i < 10; ++i)
            {
                KeyValuePair<int, int> p = new KeyValuePair<int, int>(i, i);
                refCollection.Add(p);
                hm.Insert(p.Key, p.Value);
            }

            ICollection actual = hm.ToArray();

            Assert.That(actual, Is.EquivalentTo(refCollection));
        }

        [Test]
        public void IsEmpty()
        {
            HashMap<int, string> hm = new HashMap<int, string>();
            Assert.That(hm.Empty, Is.True);

            hm.Insert(2, "sfs");

            Assert.That(hm.Empty, Is.False);
        }

        [Test]
        public void Clear()
        {
            HashMap<int, string> hm = new HashMap<int, string>();
            Assert.That(hm, Is.Empty);

            hm.Insert(2, "sfs");
            hm.Insert(3, "sfs");

            Assert.That(hm, Is.Not.Empty);

            hm.Clear();

            Assert.That(hm, Is.Empty);
        }

        [Test]
        public void Find()
        {
            HashMap<int, string> hm = new HashMap<int, string>();

            hm.Insert(2, "sfs");
            hm.Insert(3, "sfs");

            HashMap<int, string>.Iterator it = hm.Find(2);

            Assert.That(it, Is.Not.EqualTo(hm.End()));
        }
        [Test]
        public void FindFails()
        {
            HashMap<int, string> hm = new HashMap<int, string>();

            hm.Insert(2, "sfs");
            hm.Insert(3, "sfs");

            HashMap<int, string>.Iterator it = hm.Find(42);

            Assert.That(it, Is.EqualTo(hm.End()));
        }
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindFailsKeyIsNull()
        {
            HashMap<string, string> hm = new HashMap<string, string>();

            hm.Insert("1", "sfs");
            hm.Insert("3", "sfs");

            hm.Find(null);
        }

        [Test]
        public void Swap()
        {
            ICollection c1 = new KeyValuePair<int, int>[]
                {
                    new KeyValuePair<int, int>(0,1),
                    new KeyValuePair<int, int>(1,1),
                    new KeyValuePair<int, int>(2,1),
                    new KeyValuePair<int, int>(3,1),
                    new KeyValuePair<int, int>(4,1),
                };
            ICollection c2 = new KeyValuePair<int, int>[]
                {
                    new KeyValuePair<int, int>(10,1),
                    new KeyValuePair<int, int>(11,1),
                    new KeyValuePair<int, int>(12,1),
                    new KeyValuePair<int, int>(13,1),
                    new KeyValuePair<int, int>(14,1),
                };

            HashMap<int, int> hm1 = new HashMap<int, int>(c1);
            HashMap<int, int> hm2 = new HashMap<int, int>(c2);

            hm1.Swap(hm2);

            Assert.That(hm1, Is.EquivalentTo(c2));
            Assert.That(hm2, Is.EquivalentTo(c1));
        }
    }
}
